<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery.js"></script>
</head>
<body>
<h1>车辆质量投诉列表</h1>
<p>品牌：
    <select id="brandSelect">
        <c:forEach items="${brandList}" var="brand">
            <option value="${brand.brandId}">${brand.brandName}</option>
        </c:forEach>
    </select>
    <input type="button" value="查询" onclick="searchByCondition()"> <!-- 传递 event 参数 -->
    <input type="button" value="添加投诉" onclick="location.href = 'add.jsp'">
</p>
<table border="1">
    <tr>
        <th>投诉编号</th>
        <th>投诉品牌</th>
        <th>投诉问题</th>
        <th>投诉车系</th>
        <th>投诉时间</th>
        <th>投诉状态</th>
        <th>操作</th>
    </tr>
    <c:forEach items="${vehiclecomplaintsList}" var="vehiclecomplaints">
        <tr>
            <td>${vehiclecomplaints.id}</td>
            <td>${vehiclecomplaints.brandName}</td>
            <td>${vehiclecomplaints.problem}</td>
            <td>${vehiclecomplaints.carType}</td>
            <td>${vehiclecomplaints.status == 0?"信息审核":"厂家受理"}</td>
            <td>${vehiclecomplaints.complaintsTime}</td>
            <td><a href="javascript:modifyStatus(${vehiclecomplaints.status},${vehiclecomplaints.id})">编辑</a></td>
        </tr>
    </c:forEach>
</table>

<script>
    function modifyStatus(status, id) {
        $.post("update", {status: status, id: id}, res => {
            if (res > 0) {
                location.reload()
            } else {
                alert("更新失败！")
            }
        })
    }

    function searchByCondition() {

        var selectedBrandId = $('#brandSelect').val(); // 获取选中的 brandId

        location.href = "vehiclecomplaintsList?brandId="+selectedBrandId
        // $.post("vehiclecomplaintsList", {brandId: selectedBrandId}, res => {
        //     console.log(res)
        //     // location.reload()
        // })
    }

</script>
</body>
</html>
